<template>
	<view>
		<uni-section titleColor="#E20061"	 title="问题描述"  type="line" padding>
			<uni-easyinput type="textarea" v-model="formOptions.content" placeholder="请输入内容"></uni-easyinput>
		</uni-section>

		<uni-section title="图片" type="line" padding>
			<view class="dxImg" @click="shangChuan" v-if="formOptions.img"
				:style="{backgroundImage:`url(${formOptions.img})`}">
		
			</view>
			<view class="dxImg" v-else @click="shangChuan">
				<uni-icons type="cloud-upload" size="26"></uni-icons>
			</view>
		</uni-section>
	</view>
	<view style="text-align: center;margin-top: 100rpx;">
		<text class="btns" @click="saveNext">提交反馈</text>
	</view>
</template>
<script setup>
	import {ref,reactive} from "vue" 
	import { getUser } from "@/utils/token.js";
	import {onShow} from "@dcloudio/uni-app"
	import config from "@/config/config.js"
	import {addFeedback} from "@/api/user.js"
	const user = getUser()
	const formOptions = reactive({
		customer_id:0,
		content:'',
		img:''
	})
	onShow(()=>{
		formOptions.customer_id = user.id
	})
	function saveNext(){
		console.log(formOptions,35)
		addFeedback(formOptions).then(e=>{
			uni.showToast({
				title:"反馈成功！",
				success() {
					uni.navigateTo({
						url:"/mine/pages/fanKui/result"
					})
				}
			})
		})
	}
	
	function shangChuan() {
		uni.chooseImage({
			success: (chooseImageRes) => {
				const tempFilePaths = chooseImageRes.tempFilePaths;
				uni.uploadFile({
					url: config.BASE_URL + '/wxapp/upload', //仅为示例，非真实的接口地址
					filePath: tempFilePaths[0],
					name: 'file',
					success: (uploadFileRes) => {
						let res = JSON.parse(uploadFileRes.data)
						formOptions.img = res.data.path
						// console.log(formOptions, 136)
					}
				});
			}
		});
	}
</script>
<style scoped>
	.btns {
		background-color: #E60012;
		color: #fff;
		padding: 20rpx 40rpx;
		font-size: 26rpx;
		border-radius: 10rpx;
	}
	.dxImg {
		background-repeat: no-repeat;
		background-position: center;
		background-size: 100% 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 200rpx;
		height: 200rpx;
		border: 1rpx solid #ccc;
	}
	.line{
		background-color:#E60012
	}
</style>